import junit.framework.TestCase;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static java.util.Arrays.binarySearch;
import static org.junit.Assert.*;
public class StringBufferDemoTest extends TestCase {

    StringBuffer a1 = new StringBuffer("StringBuffer");
    StringBuffer a2 = new StringBuffer("StringBufferStringBuffer");
    StringBuffer a3 = new StringBuffer("StringBuffer used by 20175312");
    @Test
    public void testCharAt() throws Exception//验证是否是整个字符串中的第x个字符
    {
        assertEquals('S',a1.charAt(0));
        assertEquals('t',a2.charAt(13));
        assertEquals('b',a3.charAt(18));
    }
    @Test
    public void testcapacity() throws Exception{//验证容量
        assertEquals(28,a1.capacity());
        assertEquals(40,a2.capacity());
        assertEquals(45,a3.capacity());
    }
    @Test
    public void testlength() throws Exception{//验证字符串的长度
        assertEquals(12,a1.length());
        assertEquals(24,a2.length());
        assertEquals(29,a3.length());
    }
    @Test
    public void testindexOf(){//验证位置
        assertEquals(6,a1.indexOf("Buff"));
        assertEquals(1,a2.indexOf("tring"));
        assertEquals(25,a3.indexOf("5312"));
    }
    public void StringTester() {
        String string="aa:30:3:5";
        String[] strings=string.split(":");
        assertEquals(':',string.charAt(2));
        assertEquals("30",strings[1]);
    }
    @Test
    public void ArraysTester() {
        int[] arr={1,2,5,4};
        Arrays.sort(arr);
        assertEquals(5,arr[3]);
        assertEquals(1,binarySearch(arr,2));
    }

}